﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AioNightly.Dao;
using AioNightly.Model;

namespace AioNightly.Account
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            CheckUser();
            //RegisterHyperLink.NavigateUrl = "Register.aspx?ReturnUrl=" + HttpUtility.UrlEncode(Request.QueryString["ReturnUrl"]);
        }

        protected void lg_login_Authenticate(object sender, AuthenticateEventArgs e)
        {
            UserDAO m_userDAO = new UserDAO();
            m_user = m_userDAO.ValidateUser(lg_login.UserName,lg_login.Password);

            if (m_user!=null)
            {
                Session["User"] = m_user;
                Response.Redirect("~/Default.aspx");
            }
        }

        private User m_user;
        private void CheckUser()
        {
            m_user = (User)Session["User"];

            if (m_user != null)
            {
                Response.Redirect("~/Default.aspx");
            }
        }
    }
}
